<template>
  <Form ref="detail" :model="detail" :label-width="80" style="padding-bottom:80px;">
    <FormItem label="姓名" prop="title">
      <Input v-model="detail.name" placeholder="姓名"></Input>
    </FormItem>
    <FormItem label="报考学历" prop="报考学历">
      <Select
        v-if="educations.length > 0"
        v-model="detail.education"
        placeholder="Select category"
        style="position:relative;">
        <Option
          v-for="(edu, key) in educations"
          :key="'edu'+key"
          :value="edu">
          {{edu}}
        </Option>
      </Select>
    </FormItem>
    <FormItem label="报考学校" prop="报考学校">
      <Select
        v-if="schools.length > 0"
        v-model="detail.school"
        placeholder="Select category"
        style="position:relative;">
        <Option
          v-for="(sc, key) in schools"
          :key="'sc'+key"
          :value="sc">
          {{sc}}
        </Option>
      </Select>
    </FormItem>
  
    <FormItem>
      <Button @click="handleReset('detail')">重置</Button>
      <Button type="primary" style="margin-left: 8px" @click="handleSubmit('detail')">更新</Button>
    </FormItem>
  </Form>
</template>
<script>
  import {mapState, mapActions} from 'vuex'
  import UploadImages from '../../components/UploadImages'
  import mavonEditerUpload from '../../components/mavonEditerUpload'

  export default {
    components: {
      
    },
    computed: {
      
    },
    data() {
      return {
        id: this.$route.params.id,
        detail: this.$route.query,
        schools:[],
        educations:[]
      }
    },
    created() {
      this._getIndexDetail();
    },
    methods: {
      ...mapActions({
        getIndexDetail: 'index/indexDetail',
        updateStudent: 'student/updateStudent'
      }),

      // 获取首页详情
      async _getIndexDetail() {
        let ret = await this.getIndexDetail({isLoading:false});
      
        this.schools = ret.schools.split('|')
        this.educations = ret.educations.split('|')
      },

      // 提交
      async handleSubmit(name) {
        try {
          await this.updateStudent(this.detail);
          this.$Message.success('更新成功');
          this.$route.push('student/list')
        } catch (e) {
          // this.$Message.error('更新失败')
        }
      },
      handleReset(name) {
        this.$refs[name].resetFields();
      }
    }
  }
</script>
